package com.itheima.reggie.controller;

import com.itheima.reggie.entity.User;
import com.itheima.reggie.service.UserService;
import com.itheima.reggie.utils.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 获取验证码
     *
     * @param user 包装要获取验证码的用户手机号
     * @return String类型的通用返回结果
     */
    @PostMapping("/sendMsg")
    public Result<String> getCode(@RequestBody User user, HttpSession session) {
        return userService.getCode(user, session);
    }

    /**
     * 根据手机号和验证码登录
     * @param map 存储手机号和验证码
     * @param session 保存有手机号和验证码
     * @return User类型的通用返回结果
     */
    @PostMapping("/login")
    public Result<User> login(@RequestBody Map map, HttpSession session) {
        return userService.login(map,session);
    }
}
